﻿<%@ Page Language="C#" AutoEventWireup="false" CodeFile="recBankAccountform.aspx.cs"
    Inherits="SIPO.Web.Forms.Administration.Catalog.recBankAccountform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Bank Account Form</title>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>

    <script type="text/javascript">

        $("#btnSave").button({ icons: { primary: "ui-icon-disk"} });
        $("#btnClose").button({ icons: { primary: "ui-icon-close"} });

        $('#btnClose').click(function () {
            parent.$('#dialog').dialog("close");
        });
 
    </script>
    <script type="text/javascript">

        $(document).ready(function () {

            // 1. prepare the validation rules and messages.
            var rules = {
                txtBankCode: {
                    required: true,
                    maxlength: 10
                },
                txtBankName: "required",
                txtAccountCode: "required",
                txtAccountName: "required"
            };
            var messages = {
                txtBankCode: {
                    required: "Kode Bank harus di isi!",
                    maxlength: "Panjang maksimal Kode Bank adalah 10"
                },
                txtBankName: "Nama Bank wajib di isi!",
                txtAccountCode: "Kode Akun wajib di isi!",
                txtAccountName: "Nama Akun wajib di isi!"
            };

            $("#txtBankCode").upperCase();
            $("#txtBankCode").inputmask("Regex", { regex: "[A-Za-z-.0-9]*" });

            $("#txtBankName").inputmask("Regex", { regex: "[A-Za-z-.0-9 ]*" });            
            $("#txtAccountCode").inputmask("Regex", { regex: "[A-Za-z-.0-9]*" });
            $("#txtAccountName").inputmask("Regex", { regex: "[A-Za-z-.0-9 ]*" });
            
            $("#txtAddress1").inputmask("Regex", { regex: "[A-Za-z-.0-9 ]*" });
            $("#txtAddress2").inputmask("Regex", { regex: "[A-Za-z-.0-9 ]*" });
            $("#txtAddress3").inputmask("Regex", { regex: "[A-Za-z-.0-9 ]*" });
            $("#txtVirtualAccountCode").inputmask("Regex", { regex: "[0-9]*" });

            // 2. Initiate the validator
            var validator = new jQueryValidatorWrapper("form1", rules, messages);

            // 3. Set the click event to do the validation
            $("#btnSave").click(function () {

                if (!validator.validate())
                    return;

                var bankcode = $('#txtBankCode').val();
                var bankname = $('#txtBankName').val();
                var accountcode = $('#txtAccountCode').val();
                var accountname = $('#txtAccountName').val();
                var virtualaccountcode = $('#txtVirtualAccountCode').val();
                var address1 = $('#txtAddress1').val();
                var address2 = $('#txtAddress2').val();
                var address3 = $('#txtAddress3').val();

                var isactive = "0";
                var checkIsActive = document.getElementById("chkIsActive");
                if (checkIsActive.checked) {
                    isactive = "1";
                }
                else {
                    isactive = "0";
                }

                var id = $('#<%= hfID.ClientID %>').val();

                var objrecBankAccount = new Object();
                objrecBankAccount.BankID = id;
                objrecBankAccount.BankCode = encodeURIComponent(bankcode);
                objrecBankAccount.BankName = encodeURIComponent(bankname);
                objrecBankAccount.AccountCode = encodeURIComponent(accountcode);
                objrecBankAccount.AccountName = encodeURIComponent(accountname);
                objrecBankAccount.VirtualAccountCode = encodeURIComponent(virtualaccountcode);
                objrecBankAccount.Address1 = encodeURIComponent(address1);
                objrecBankAccount.Address2 = encodeURIComponent(address2);
                objrecBankAccount.Address3 = encodeURIComponent(address3);
                objrecBankAccount.IsActive = encodeURIComponent(isactive);

                jsonData = JSON.stringify(objrecBankAccount);
                var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/administration/catalog/recBankAccounthandler.ashx") %>';
                if (id == 0)
                    CallAjax(handlerUrl, "?method=insert", jsonData);
                else {
                    CallAjax(handlerUrl, "?method=update", jsonData);
                }

                parent.$('#dialog').dialog('close');

                setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);

                return false;
            });
        });
    
    </script>
    <script type="text/javascript">

        function ClearText() {
            $('#txtBankCode').val('');
            $('#txtBankName').val('');
            $('#txtAccountCode').val('');
            $('#txtAccountName').val('');
            $('#txtAddress1').val('');
            $('#txtAddress2').val('');
            $('#txtAddress3').val('');
        }        
         
    </script>
</head>
<body onload="ClearText();">
    <form id="form1" runat="server">
    <table border="0">
        <tr>
            <td style="width: 50">
                Kode Bank
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtBankCode" MaxLength="10" runat="server" Width="200"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td>
                Nama Bank
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtBankName" runat="server" Width="300" MaxLength="100"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td>
                Kode Akun
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtAccountCode" runat="server" Width="300" MaxLength="50"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Nama Akun
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtAccountName" runat="server" Width="300" MaxLength="100"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Kode Virtual Akun
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtVirtualAccountCode" runat="server" Width="300" MaxLength="5"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Alamat 1
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtAddress1" TextMode="MultiLine" runat="server" Width="300" Rows="2"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Alamat 2
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtAddress2" TextMode="MultiLine" runat="server" Width="300" Rows="2"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Alamat 3
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtAddress3" TextMode="MultiLine" runat="server" Width="300" Rows="2"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Aktif
            </td>
            <td>
                :
            </td>
            <td>
                <asp:CheckBox ID="chkIsActive" runat="server" />
            </td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td>
                <div style="text-align: right; padding-top: 10px;">
                    <button id="btnSave" type="button">
                        Save</button>
                    <button id="btnClose" type="button">
                        Close</button>
                </div>
            </td>
        </tr>
        <tr>
            <td></td><td></td>
            <td>
                <asp:HiddenField ID="hfID" runat="server" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
